home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: king.mcs.drexel.edu!ucphinni
- From: ucphinni@mcs.drexel.edu (C. K. Phinnizee)
- Subject: Implicit Typecasting
- Message-ID: <1996Mar16.203628.15187@mcs.drexel.edu>
- Sender: news@mcs.drexel.edu
- Organization: Drexel University, Dept. of Math. and Comp. Sci.
- X-Newsreader: TIN [version 1.2 PL2]
- Date: Sat, 16 Mar 96 20:36:28 GMT
-
- I am trying to write a personalized C++ library using Codewarrior on the
- Mac platform (the type of platform should not matter. My main concern is
- portability, followed closely by speed.).
- The library is going to have all of the basic structures such as a
- linked list node, different types of stacks, different types of trees,
- ...etc... and some higher order classes, like scheduling algorithms. I
- have had some success, but there is one nagging question that has been
- bothering me.
- In many of my classes, I use inheritence and must change the interface
- so the client need not worry about the implementation details (standard c++
- practice) about the interface. For example, in one part of my library, I
- have something like this:
-
- class llNode {
- typedef llNode ll;
- public:
- llNode(ll * anext = NULL) { nextptr = anext;}
- ll * next(void) { return nextptr;}
- ll * next(ll * anext) { return nextptr = anext;}
- ... cut code ...
- private:
- ll * nextptr;
- };
-
- class dlNode : public llNode {
- typedef dlNode dl;
- public:
- dlNode(dl * aprev = NULL,dl * anext = NULL) : ll((ll *) anext)
- { prevptr = aprev;}
- dl * prev(void) { return (dl *) prevptr.next();}
- dl * prev(dl * aprev) { return (dl *) prevptr.next((dl *) aprev);}
- dl * next(void) { return (dl *) ll::next();}
- dl * next(dl * anext) { return (dl *) ll::next((ll *) anext);}
- }
- private:
- ll prevptr;
- };
-
- My question is of a readability more than a functionality concern. For
- the above code, it would seem to me that a lot of meaningless code (just
- typecasting) is being done. Is there any standard way to eliminate this.
- In other words, is there a way for the compiler to automatically equate the
- current class to the superclass and compile it without any warnings (i.e.
- compiler would replace ll for dl in the abovemented case) In the previous
- case, this would elimate all of the public member functions in the dlNode.
-
- Thank you in advance for your response.
-
- P.S. I once did something similar to what I was asking but it was not
- portable. I have since forgoten how I did it but I believe it went
- something like this.
-
- class dlNode : public llNode {
- ... stuff ...
- public:
- operator llNode();
- // I am not sure whether you have to protype the
- // operator with anything. If you have to are it is
- // left as an option. Please let me know.
- }
-
- but when I tried this at home, it did not work. I am not for certain, but
- I believe this works with g++ or something like it.
-
- Is there something more that I have to provide for this to work, or is
- this a special feature of the compiler. (Anything for gnu tells to sport
- fancy features and this might be one of them)
-
-
-
- --
- "Skool iz kool..."
-